﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FlyGenerator : MonoBehaviour {

	public GameObject flyPrefab;

	private float delayTime = 2;
	private float currentTime = 0;
	// Use this for initialization
	void Start () {
		currentTime = 0;
	}
	
	// Update is called once per frame
	void Update () {
		if (currentTime < delayTime) {
			currentTime += Time.deltaTime;
		}
		if (currentTime >= delayTime && transform.childCount <= 0) {
			currentTime = 0f;
			var v = Random.value;
			if (v <= 0.8) {
				FlyTrigger trigger = Instantiate (flyPrefab, transform).GetComponent<FlyTrigger> ();
				trigger.transform.parent = transform;
				var pos = Camera.main.ScreenToWorldPoint (new Vector3(Screen.width+50, Screen.height/8f*6f, 0));
				trigger.transform.position = new Vector3(pos.x, pos.y, 0);
			}
		}
	}
}
